from langchain.chains import LLMChain
from langchain.chat_models import ChatOpenAI
import os

from langchain.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, \
    ChatPromptTemplate
chat = ChatOpenAI(temperature=0)
template = "You are a helpful assistant that translates mandarin to English."
system_message_prompt = SystemMessagePromptTemplate.from_template(template=template)
example_human = HumanMessagePromptTemplate.from_template("你好啊，老师！")
example_ai = AIMessagePromptTemplate.from_template("Argh me mateys")
human_template = "{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)

chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, example_human, example_ai, human_message_prompt])
output = chat_prompt.format(input_languge="English")
chain = LLMChain(llm=chat, prompt=chat_prompt)
response = chain.run("我爱编程")
print(response)

# 作为字符串
# output_1 = chat_prompt.format(input_language="English", output_language="French", text="I love programming")
# output_2 = chat_prompt.format_prompt(input_language="English", output_language="French", text="I love programming.").to_string()
#
# jinja2_template = "Tell me a {{adjective}} joke about {{content}}"
# prompt_template = PromptTemplate.from_template(template=jinja2_template, template_format="jinja2")
# prompt_template.format(adjective="funny", content="chickens")